/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbsetup;

import java.util.ArrayList;

import prototype.persistence.GoalDAO;
import prototype.persistence.MapDAO;
import prototype.persistence.PositionDAO;
import prototype.persistence.ScenarioDAO;
import prototype.persistence.UnitDAO;
import prototype.persistence.UserDAO;
import prototype.persistence.UserHasUnitDAO;
import prototype.persistence.hibernate.GoalHibernateDAO;
import prototype.persistence.hibernate.MapHibernateDAO;
import prototype.persistence.hibernate.PositionHibernateDAO;
import prototype.persistence.hibernate.ScenarioHibernateDAO;
import prototype.persistence.hibernate.UnitHibernateDAO;
import prototype.persistence.hibernate.UserHasUnitHibernateDAO;
import prototype.persistence.hibernate.UserHibernateDAO;
import prototype.persistence.pojo.Goal;
import prototype.persistence.pojo.Scenario;
import prototype.persistence.pojo.Unit;
import prototype.persistence.pojo.User;
import prototype.persistence.pojo.UserHasUnit;
import prototype.persistence.pojo.Map;
import prototype.persistence.pojo.Position;

/**
 *
 * @author Server
 */
public class DBSetup {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        createUnits();
        User terror = new User();
        terror.setName("Guerilla");
        User police = new User();
        police.setName("Police");
        User invis = new User();
        invis.setName("Civilians");

        Map m = new Map();
        m.setName("Prototype Map");

        Position pos = new Position();
        PositionDAO posDao = new PositionHibernateDAO();
        posDao.save(pos);


        MapDAO mapDao = new MapHibernateDAO();
        mapDao.save(m);

        Scenario scenario = new Scenario();
        scenario.setUsers(new ArrayList<User>());
        scenario.getUsers().add(police);
        scenario.getUsers().add(terror);
        scenario.setName("Prototype");
        scenario.setMap(m);

        police.setScenario(scenario);
        terror.setScenario(scenario);
        invis.setScenario(scenario);

        Goal terrorG = new Goal();
        terrorG.setType(0); //Annihilate enemy
        terrorG.setUser(terror);
        terrorG.setName("Annihilate enemy");
        terror.setGoals(new ArrayList<Goal>());
        terror.getGoals().add(terrorG);

        Goal policeG1 = new Goal();
        policeG1.setType(0); //Annihilate enemy
        policeG1.setUser(police);
        policeG1.setName("Annihilate enemy");
        police.setGoals(new ArrayList<Goal>());
        police.getGoals().add(policeG1);

        Goal policeG2 = new Goal();
        policeG2.setType(1); //Protect civilians
        policeG2.setCivilLimit(0);
        policeG2.setUser(police);
        policeG2.setName("Protect Civilians");
        police.getGoals().add(policeG2);

        ScenarioDAO sceDao = new ScenarioHibernateDAO();
        sceDao.save(scenario);

        UserDAO userDAO = new UserHibernateDAO();
        userDAO.save(police);
        userDAO.save(terror);
        userDAO.save(invis);

        UnitDAO unDao = new UnitHibernateDAO();
        userHasUnit(police, unDao.findByName("Police Infantry").get(0), pos);
        userHasUnit(police, unDao.findByName("Sniper").get(0), pos);
        userHasUnit(terror, unDao.findByName("Terror Infantry").get(0), pos);
        userHasUnit(invis, unDao.findByName("Civilian").get(0), pos);
        userHasUnit(invis, unDao.findByName("Civilian").get(0), pos);

        GoalDAO goalDao = new GoalHibernateDAO();
        goalDao.save(terrorG);
        goalDao.save(policeG1);
        goalDao.save(policeG2);





    }

    public static void userHasUnit(User u, Unit un, Position pos) {
        UserHasUnit uhu = new UserHasUnit();
        uhu.setUser(u);
        uhu.setUnit(un);
        uhu.setPosition(pos);
        if (u.getUserHasUnits() == null) {
            u.setUserHasUnits(new ArrayList<UserHasUnit>());
        }
        u.getUserHasUnits().add(uhu);

        UserHasUnitDAO uhuDao = new UserHasUnitHibernateDAO();
        uhuDao.save(uhu);
    }

    public static void createUnits() {
        Unit sniper = new Unit();
        sniper.setName("Sniper");
        sniper.setRangeDistance(1000);
        sniper.setHealth(100);
        sniper.setFirePower(50);
        sniper.setFireEffectRadius(1);
        sniper.setAccuracy(95);
        sniper.setReloadTime(15);

        Unit infantry = new Unit();
        infantry.setName("Police Infantry");
        infantry.setClassName("deneme");
        infantry.setJessFile("deneme");
        infantry.setModelFile("deneme");
        infantry.setMovementRate(0);
        infantry.setArmor(5);
        infantry.setRangeDistance(200);
        infantry.setHealth(100);
        infantry.setFirePower(30);
        infantry.setFireEffectRadius(10);
        infantry.setAccuracy(95);
        infantry.setReloadTime(10);

        Unit civil = new Unit();
        civil.setName("Civilian");
        civil.setRangeDistance(0);
        civil.setHealth(80);
        civil.setFirePower(0);
        civil.setFireEffectRadius(0);
        civil.setAccuracy(0);
        civil.setReloadTime(0);

        Unit terrorInfantry = new Unit();
        terrorInfantry.setName("Terror Infantry");
        terrorInfantry.setRangeDistance(250);
        terrorInfantry.setHealth(100);
        terrorInfantry.setFirePower(50);
        terrorInfantry.setFireEffectRadius(15);
        terrorInfantry.setAccuracy(70);
        terrorInfantry.setReloadTime(10);



        UnitDAO unitDao = new UnitHibernateDAO();
        unitDao.save(infantry);
        unitDao.save(terrorInfantry);
        unitDao.save(sniper);
        unitDao.save(civil);
    }
}

